package thread;

// 获取当前线程的引用
public class demo12 {
    public static void main(String[] args) {
        // 1
        Thread t = new Thread(){
            @Override
            public void run() {
                System.out.println(this.getName());
            }
        };
        t.start();

        // 2
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                // 当前获取线程的引用是 Runnable 中的
                // System.out.println(this.getName());
                Thread cur = Thread.currentThread();
                System.out.println(cur.getName());
            }
        });
        t2.start();

        // 3
        Thread t3 = new Thread(() -> {
            // System.out.println(this.getName());
            Thread cur = Thread.currentThread();
            System.out.println(cur.getName());
        });
        t3.start();

    }
}
